//
//  Config.h
//  YYDemo
//
//  Created by lipeng on 2019/4/20.
//  Copyright © 2019 lipeng. All rights reserved.
//

#ifndef Config_h
#define Config_h

//条件编译
#if __has_feature(objc_arc)
    //ARC
    //.h头文件中的单例宏
    #define IMSingletonH(name) + (instancetype)shared##name;
    //.m文件中的单例宏
    #define IMSingletonM(name) \
    static id _instance;\
    + (instancetype)allocWithZone:(struct _NSZone *)zone{\
    static dispatch_once_t onceToken;\
    dispatch_once(&onceToken, ^{\
    _instance = [super allocWithZone:zone];\
    });\
    return _instance;\
    }\
    + (instancetype)shared##name{\
    static dispatch_once_t onceToken;\
    dispatch_once(&onceToken, ^{\
    _instance = [[self alloc] init];\
    });\
    return _instance;\
    }\
    - (id)copyWithZone:(NSZone *)zone{\
    return _instance;\
    }
#else //MRC
    //.h头文件中的单例宏
    #define IMSingletonH(name) + (instancetype)shared##name;
    //.m文件中的单例宏
    #define IMSingletonM(name) \
    static id _instance;\
    + (instancetype)allocWithZone:(struct _NSZone *)zone{\
    static dispatch_once_t onceToken;\
    dispatch_once(&onceToken, ^{\
    _instance = [super allocWithZone:zone];\
    });\
    return _instance;\
    }\
    + (instancetype)shared##name{\
    static dispatch_once_t onceToken;\
    dispatch_once(&onceToken, ^{\
    _instance = [[self alloc] init];\
    });\
    return _instance;\
    }\
    - (id)copyWithZone:(NSZone *)zone{\
    return _instance;\
    }\
    - (oneway void)release{\
    }\
    - (instancetype)retain{\
    return self;\
    }\
    - (NSUInteger)retainCount{\
    return 1;\
    }\
    - (instancetype)autorelease{\
    return self;\
    }
 #endif

#ifndef LOCK
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
#endif

#ifndef UNLOCK
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
#endif


#define App  [UIApplication sharedApplication]

#endif /* Config_h */
